package com.business.exam.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.business.exam.domain.ExamQbCategory;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.business.common.annotation.Log;
import com.business.common.core.controller.BaseController;
import com.business.common.core.domain.AjaxResult;
import com.business.common.enums.BusinessType;
import com.business.exam.domain.ExamQbKnownledgeLabel;
import com.business.exam.service.IExamQbKnownledgeLabelService;
import com.business.common.utils.poi.ExcelUtil;
import com.business.common.core.page.TableDataInfo;

/**
 * 知识点标签Controller
 *
 * @author zhanglele
 * @date 2023-11-17
 */
@RestController
@RequestMapping("/questionbank/knowledgeLabel")
public class ExamQbKnownledgeLabelController extends BaseController
{
    @Autowired
    private IExamQbKnownledgeLabelService examQbKnownledgeLabelService;

    /**
     * 获取题库分类树列表
     */
    //@PreAuthorize("@ss.hasPermi('questionbank:label:tree')")
    @GetMapping("/tree")
    public AjaxResult knownledgeLabelTree(ExamQbKnownledgeLabel examQbKnownledgeLabel)
    {
        return success(examQbKnownledgeLabelService.selectKnownledgeLabelTreeList(examQbKnownledgeLabel));
    }



    /**
     * 查询知识点标签列表
     */
    //@PreAuthorize("@ss.hasPermi('questionbank:knowledgeLabel:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExamQbKnownledgeLabel examQbKnownledgeLabel)
    {
        startPage();
        List<ExamQbKnownledgeLabel> list = examQbKnownledgeLabelService.selectExamQbKnownledgeLabelList(examQbKnownledgeLabel);
        return getDataTable(list);
    }

    /**
     * 导出知识点标签列表
     */
    //@PreAuthorize("@ss.hasPermi('questionbank:knowledgeLabel:export')")
    @Log(title = "知识点标签", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExamQbKnownledgeLabel examQbKnownledgeLabel)
    {
        List<ExamQbKnownledgeLabel> list = examQbKnownledgeLabelService.selectExamQbKnownledgeLabelList(examQbKnownledgeLabel);
        ExcelUtil<ExamQbKnownledgeLabel> util = new ExcelUtil<ExamQbKnownledgeLabel>(ExamQbKnownledgeLabel.class);
        util.exportExcel(response, list, "知识点标签数据");
    }

    /**
     * 获取知识点标签详细信息
     */
   // @PreAuthorize("@ss.hasPermi('questionbank:knowledgeLabel:query')")
    @GetMapping(value = "/{labelId}")
    public AjaxResult getInfo(@PathVariable("labelId") Long labelId)
    {
        return success(examQbKnownledgeLabelService.selectExamQbKnownledgeLabelByLabelId(labelId));
    }

    /**
     * 新增知识点标签
     */
    //@PreAuthorize("@ss.hasPermi('questionbank:knowledgeLabel:add')")
    @Log(title = "知识点标签", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExamQbKnownledgeLabel examQbKnownledgeLabel)
    {
        return toAjax(examQbKnownledgeLabelService.insertExamQbKnownledgeLabel(examQbKnownledgeLabel));
    }

    /**
     * 修改知识点标签
     */
    //@PreAuthorize("@ss.hasPermi('questionbank:knowledgeLabel:edit')")
    @Log(title = "知识点标签", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExamQbKnownledgeLabel examQbKnownledgeLabel)
    {
        return toAjax(examQbKnownledgeLabelService.updateExamQbKnownledgeLabel(examQbKnownledgeLabel));
    }

    /**
     * 删除知识点标签
     */
    //@PreAuthorize("@ss.hasPermi('questionbank:knowledgeLabel:remove')")
    @Log(title = "知识点标签", businessType = BusinessType.DELETE)
	@DeleteMapping("/{labelIds}")
    public AjaxResult remove(@PathVariable Long[] labelIds)
    {
        return toAjax(examQbKnownledgeLabelService.deleteExamQbKnownledgeLabelByLabelIds(labelIds));
    }
}
